package com.winsdom.controller;

import com.winsdom.annotation.OperationLog;
import com.winsdom.dto.LoginDto;
import com.winsdom.dto.ResetPasswordDTO;
import com.winsdom.exception.BaseException;
import com.winsdom.properties.JwtProperties;
import com.winsdom.result.Result;
import com.winsdom.service.LoginService;
import com.winsdom.vo.LoginVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/login")
@Slf4j
@Api(tags = "用户登录接口", description = "用户登录相关接口")
public class LoginController {
    @Autowired
    private JwtProperties jwtProperties;
    @Autowired
    private LoginService loginService;
    // QQ 邮箱配置
    private static final String SMTP_HOST = "smtp.qq.com";
    private static final int SMTP_PORT = 465;
    private static final String EMAIL_FROM = "your_qq_email@qq.com";
    private static final String EMAIL_PASSWORD = "your_qq_email_smtp_password";

    @PostMapping
    @ApiOperation(value = "登录接口", notes = "登录接口")
    @OperationLog(description = "用户登录")
    public Result login(@RequestBody LoginDto loginDTO) {
        //登录成功，返回用户的所有信息
         LoginVo loginVo = loginService.login(loginDTO);
      return Result.success(loginVo);
    }

    @Operation(summary = "重置密码")
    @PostMapping("/resetPassword")
    @OperationLog(description = "用户重置密码")
    public Result resetPassword(@RequestBody ResetPasswordDTO resetPasswordDTO) {
        try {
            loginService.resetPassword(resetPasswordDTO);
            return Result.success("密码重置成功");
        } catch (BaseException e) {
            return  Result.error(e.getMessage());
        }
    }
}